package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.TripOrderBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class TripMeAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<TripOrderBean> datalist;
    private TextView notv;
    private int tPos;

    public TripMeAdapter(Context context, ArrayList<TripOrderBean> datalist, TextView notv, int tPos) {
        this.context = context;
        this.datalist = datalist;
        this.notv = notv;
        this.tPos = tPos;
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_trip_me, parent, false);
        return new TripHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        TripHolder tripHolder = (TripHolder) holder;
        if (tPos == 1) {
            tripHolder.filmMoneysignTv.setTextColor(context.getResources().getColor(R.color.colorMainGray6));
            tripHolder.filmMoneyTv.setTextColor(context.getResources().getColor(R.color.colorMainGray6));
            tripHolder.filmTimeTv.setTextColor(context.getResources().getColor(R.color.colorMainGray6));
            tripHolder.tripCannumTv.setTextColor(context.getResources().getColor(R.color.colorMainGray6));
            tripHolder.tripRemainnumTv.setTextColor(context.getResources().getColor(R.color.colorMainGray6));
        }

        TripOrderBean tripOrderBean = datalist.get(position);
        tripHolder.filmNameTv.setText(tripOrderBean.getStart_place()+"-"+tripOrderBean.getDestination());
        tripHolder.filmMoneyTv.setText(tripOrderBean.getOld_money());
        tripHolder.filmTimeTv.setText("时间："+tripOrderBean.getStarttime());
        tripHolder.tripCannumTv.setText("车牌号："+tripOrderBean.getBus_no());
        tripHolder.tripRemainnumTv.setText("购买座位："+tripOrderBean.getNum()+"位");


        tripHolder.itemTrip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onOneClick != null) {
                    onOneClick.oneClick(position);
                }
            }
        });


    }

    @Override
    public int getItemCount() {
        int iCount = datalist == null ? 0 : datalist.size();
        if (iCount == 0) {
            notv.setVisibility(View.VISIBLE);
        } else {
            notv.setVisibility(View.GONE);
        }
          return iCount;
    }

    class TripHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.film_name_tv)
        TextView filmNameTv;
        @BindView(R.id.film_time_tv)
        TextView filmTimeTv;
        @BindView(R.id.film_moneysign_tv)
        TextView filmMoneysignTv;
        @BindView(R.id.film_money_tv)
        TextView filmMoneyTv;
        @BindView(R.id.trip_cannum_tv)
        TextView tripCannumTv;
        @BindView(R.id.trip_remainnum_tv)
        TextView tripRemainnumTv;
        @BindView(R.id.item_trip)
        ConstraintLayout itemTrip;

        TripHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
